﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Signup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    UserBLL usr = new UserBLL();
    protected void btnDangKy_Click(object sender, EventArgs e)
    {
        int user = 1;
        if (checkUser())
        {
            user = 0;
        }
        else
        {
            lbLoiTK.Text = "Tài Khoản đã tồn tài!";
        }
        int email = 1;
        if (checkEmail())
        {
            email = 0;
        }
        else
        {
            lbLoiEmail.Text = "Email đã tồn tại";
        }
        if (user==0&&email==0&&txtHoTen.Text!=""&&txtTenTK.Text!=""&&txtMK.Text!=""&&txtMK2.Text!=""&&usr.signupUser(txtTenTK.Text.Trim(), txtMK.Text.Trim(), txtHoTen.Text, txtEmail.Text, txtDienThoai.Text, txtDiaChi.Text))
        {
            Session["Username"] = txtTenTK.Text;
            Response.Redirect("Default.aspx");
        }
        else
        {
            lbLoi.Text = "Kiểm tra lại thông tin đăng ký";
        }
    }
    public bool checkUser()
    {
        if(usr.checkExistUser(txtTenTK.Text.Trim()))
        {
            return false;
        }
        else
	    {
            return true;
	    }
    }
    public bool checkEmail()
    {
        if(usr.checkExistEmail(txtEmail.Text.Trim()))
        {
            return false;
        }
        else
	    {
            return true;
	    }
    }
}